{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fdb79b6e",
   "metadata": {},
   "source": [
    "· 日期：2022-11-16\\week13(周三)\n",
    "\n",
    "· 课程：python\n",
    "\n",
    "· 记录人：林荣烽"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60ad0291",
   "metadata": {},
   "source": [
    "## P61 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec12aec4",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4b4415c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ff38905a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: Milliways\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4904b430",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: Hitch-hiker\n",
      "i\n",
      "e\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "49ef08fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: Galaxy\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "07d39d78",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: Sky\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51f33e25",
   "metadata": {},
   "source": [
    "## P67 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "73c8dd60",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "03147917",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e36cf9a",
   "metadata": {},
   "source": [
    "## P81 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7e71f530",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8b6d99d",
   "metadata": {},
   "source": [
    "* 标注：列表切片是非破坏性的，因为从一个现有列表中抽取对象不会改变原来的列表，原数据仍保持不变。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5834a58",
   "metadata": {},
   "source": [
    "## P83 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9d380985",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d86fac37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60d14c23",
   "metadata": {},
   "source": [
    "## P89列表：更新我们已经知道些什么"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57ade455",
   "metadata": {},
   "source": [
    "|  列表的方法 |  Description  |     使用方法    |      备注     |\n",
    "| ----------  | ------------------| ------------------- | ----------------- |\n",
    "|  append  |   Append object to the end of the list.  | list.append(object) | 注意：增加在末尾！|\n",
    "|  clear  |    Remove all items from list.| list.clear(self)| 注意：将元素清空|\n",
    "|  copy   |   Return a shallow copy of the list.   | list.copy(self)  |注意：不等价于 = |\n",
    "|  count   |  Return number of occurrences of value. | list.count(self,value)  | 注意：返回的是某个元素在列表里面的个数 |\n",
    "|  extend  |  Extend list by appending elements from the iterable.  | list.extend(self, iterable) | 注意：在list的末尾添加元素 |\n",
    "|  index   | Return first index of value.  | list.index(self, value)  | 注意：返回的是元素在列表中的第一个位置 |\n",
    "|  insert  | Insert object before index.   | list.insert(self, index, object)   |注意： 向指定的地方添加元素 |\n",
    "|  pop   |  Remove and return item at index (default last). | list.pop(self, index=-1)  |注意：删除列表尾部的元素,返回删除的元素 |\n",
    "|  remove |  Remove first occurrence of value. | list.remove(self, value) | 注意：删除的是第一次出现的元素，如果元素不存在会报错  |\n",
    "|  reverse  | Reverse *IN PLACE*.    | list.reverse(self) | 注意：将列表进行翻转  |\n",
    "|  sort    | Sort the list in ascending order and return None. |list.sort(self)|注意：对列表进行排序，反向标志可以设置为按降序排序 |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5732437a",
   "metadata": {},
   "source": [
    "|  列表 | 总结  | \n",
    "| ----------  | ------------------|\n",
    "|1.|列表认识中括号记法，可以用中括号来记法从任何列表选择单个对象。|\n",
    "|2.|与很多其他编程语言类似，Python从0开始计数，所以列表中的第一个对象位于索引位置0，第2个对象处于索引位置1。|\n",
    "|3.|Python允许从任意两端索引列表。使用-1会选择列表中的最后一项，-2会选择倒数第2个对象。|\n",
    "|4.|列表支持在中括号记法中指定开始、结束和步长值，可以提供列表的切片（或片段）。|\n",
    "|5.|只要需要存储任何相关对象的一个集合，列表就是很好的选择。|\n",
    "|6.|如果有一组类似的对象，需要把它们存储在一个数据结构中，列表就是理想的选择。|\n",
    "|7.|列表很擅长存储相关字母的集合，如vowels列表。如果数据是一个数字集合，列表也是很好的选择。|\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f89af3e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
